home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / human interface toolbox / vertest / vertest.c next >
Encoding:
C/C++ Source or Header  |  2000-06-23  |  11.2 KB  |  433 lines

  1. /*
  2.     File:        Vertest.c
  3.  
  4.     Contains:    The app will display the information from the Vers Resource.
  5.  
  6.     Written by: RICHARD P. COLLYER    
  7.  
  8.     Copyright:    Copyright © 1987-1999 by Apple Computer, Inc., All Rights Reserved.
  9.  
  10.                 You may incorporate this Apple sample source code into your program(s) without
  11.                 restriction. This Apple sample source code has been provided "AS IS" and the
  12.                 responsibility for its operation is yours. You are not permitted to redistribute
  13.                 this Apple sample source code as "Apple sample source code" after having made
  14.                 changes. If you're going to re-distribute the source, we require that you make
  15.                 it clear in the source that the code was descended from Apple sample source
  16.                 code, but that you've made changes.
  17.  
  18.     Change History (most recent first):
  19.                 8/9/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  20.                 
  21.  
  22. */
  23.  
  24. #include    <CType.h>
  25. #include    <Quickdraw.h>
  26. #include    <Windows.h>
  27. #include    <OSUtils.h>
  28. #include    <Controls.h>
  29. #include    <desk.h>
  30. #include    <dialogs.h>
  31. #include    <Events.h>
  32. #include    <Files.h>
  33. #include     <Fonts.h>
  34. #include    <Memory.h>
  35. #include    <Menus.h>
  36. #include    <Notification.h>
  37. #include    <OSEvents.h>
  38. #include    <Packages.h>
  39. #include    <Palettes.h>
  40. #include     <Processes.h>
  41. #include    <Resources.h>
  42. //#include    <SANE.h>
  43. #include    <SegLoad.h>
  44. #include    <Sound.h>
  45. #include    <String.h>
  46. #include    <ToolUtils.h>
  47. #include    <StdIO.h>
  48. #include    <math.h>
  49. #include    <TextUtils.h>
  50.  
  51. extern _DataInit();
  52.  
  53. #define    TRUE            0xFF
  54. #define    FALSE            0
  55. #define    VERSION            1
  56. #define    SR_BIT            0
  57.  
  58. #define    appleID            128            
  59. #define    appleMenu        0
  60. #define    aboutMeCommand    1
  61.  
  62. #define    fileID            129
  63. #define    startCommand    1
  64. #define    quitCommand     2
  65.  
  66. #define    editID            130
  67.  
  68. #define    aboutMeDLOG        128
  69. #define    okButton        1
  70. #define    authorItem        2
  71. #define    languageItem    3
  72.  
  73. #define    nocolorID        130
  74. #define    no68020            133
  75. #define    no68881            132
  76. #define    no256            134
  77. #define    nosys6            135
  78.  
  79. long                Tick;
  80. int                    yieldTime, err, numcolor, offLeft, offTop, offRight, offBottom;
  81. Rect                screenRect, BaseRect, TotalRect, minRect;
  82. WindowPtr            whichWindow, myWindow;
  83. CTabHandle            mycolors;
  84. PaletteHandle        srcPalette;
  85. MenuHandle            mymenu1, mymenu2, mymenu0;
  86. EventRecord         myEvent;
  87. Boolean                DoneFlag;
  88. GDHandle            theGDevice;
  89. SysEnvRec            theWorld;
  90. OSErr                OSys;
  91.  
  92. void start(void);
  93. void showAboutMeDialog(void);
  94. void init(void);
  95. void doCommand(long mResult);
  96.  
  97. /*______________________________________________________*/
  98. /*                What ever You want                    */
  99. /*______________________________________________________*/
  100. void start()
  101. {
  102.  
  103.     VersRecHndl version;
  104.     StringPtr messagePtr;
  105.     Str255 longMessage, countsstrPtr;
  106.     //char *countsstrPtr, countstr;
  107.     
  108.     //countsstrPtr = &countstr;
  109.  
  110.     version = (VersRecHndl) GetResource ('vers', 1);
  111.     
  112.     messagePtr = (StringPtr) (((unsigned long) &(**version).shortVersion[1]) + 
  113.             ((**version).shortVersion[0]));
  114.  
  115.     BlockMove((Ptr) messagePtr, &longMessage, ((unsigned char) *messagePtr) + 1);
  116.  
  117. //short version
  118.     MoveTo(10,10);
  119.     DrawString((**version).shortVersion);
  120. //long version
  121.     MoveTo(10,30);
  122.     DrawString(longMessage);
  123. //country code
  124.     MoveTo(10,50);
  125.     NumToString((**version).countryCode,countsstrPtr);
  126.     DrawString(countsstrPtr);
  127. //major rev
  128.     MoveTo(10,70);
  129.     NumToString((**version).numericVersion.majorRev,countsstrPtr);
  130.     DrawString(countsstrPtr);
  131. // minorAndBugRev
  132.     MoveTo(10,90);
  133.     NumToString((**version).numericVersion.minorAndBugRev,countsstrPtr);
  134.     DrawString(countsstrPtr);
  135. //stage
  136.     MoveTo(10,110);
  137.     NumToString((**version).numericVersion.stage,countsstrPtr);
  138.     DrawString(countsstrPtr);
  139. // non rel rev
  140.     MoveTo(10,130);
  141.     NumToString((**version).numericVersion.nonRelRev,countsstrPtr);
  142.     DrawString(countsstrPtr);
  143.     
  144.     return;
  145. }
  146.  
  147. /*______________________________________________________*/
  148. /*                 About Prog Dialog                    */
  149. /*______________________________________________________*/
  150. void showAboutMeDialog()
  151. {
  152.     GrafPtr     savePort;
  153.     DialogPtr    theDialog;
  154.     short        itemHit;
  155.  
  156.     GetPort(&savePort);
  157.     theDialog = GetNewDialog(aboutMeDLOG, nil, (WindowPtr) -1);
  158.     SetPort(theDialog);
  159.  
  160.     do {
  161.         ModalDialog(nil, &itemHit);
  162.     } while (itemHit != okButton);
  163.  
  164.     CloseDialog(theDialog);
  165.  
  166.     SetPort(savePort);
  167.     return;
  168. }
  169.  
  170. /*______________________________________________________*/
  171. /*                 Do Menu Function                     */
  172. /*______________________________________________________*/
  173. void doCommand(mResult)
  174.     long    mResult;
  175. {
  176.     int                     theMenu, theItem;
  177.     char                    daName[256];
  178.     GrafPtr                 savePort;
  179.  
  180.     theItem = LoWord(mResult);
  181.     theMenu = HiWord(mResult);
  182.     
  183.     switch (theMenu) {
  184. /*______________________________________________________*/
  185. /*                    Do Apple Menu                     */
  186. /*______________________________________________________*/
  187.         case appleID:
  188.             if (theItem == aboutMeCommand)
  189.                 showAboutMeDialog();
  190.             else {
  191.                 GetMenuItemText(mymenu0, theItem, (unsigned char*)daName);
  192.                 GetPort(&savePort);
  193.                 (void) OpenDeskAcc((unsigned char*)daName);
  194.                 SetPort(savePort);
  195.             }
  196.             break;
  197. /*______________________________________________________*/
  198. /*                     Do File Menu                     */
  199. /*______________________________________________________*/
  200.         case fileID:
  201.             switch (theItem) {
  202.                 case startCommand:
  203.                     start();
  204.                     break;
  205.                 case quitCommand:
  206.                     DoneFlag = TRUE;
  207.                     break;
  208.                 default:
  209.                     break;
  210.                 }
  211.             break;
  212. /*______________________________________________________*/
  213. /*                     Do Edit Menu                     */
  214. /*______________________________________________________*/
  215.         case editID:
  216.             switch (theItem) {
  217.                 default:
  218.                     break;
  219.                 }
  220.             break;
  221.         default:
  222.             break;
  223.         }
  224.     HiliteMenu(0);
  225.     return;
  226. }
  227.  
  228.  
  229. /*______________________________________________________*/
  230. /*               Initialization traps                   */
  231. /*______________________________________________________*/
  232. void init()
  233. {
  234.     RgnHandle        tempRgn;
  235.     
  236.     //commented out UnloadSeg for MetroWerks compiler
  237.     //UnloadSeg(_DataInit);
  238.     InitGraf(&qd.thePort);
  239.     FlushEvents(everyEvent, 0);
  240.     InitWindows();
  241.     InitDialogs(nil);
  242.     InitCursor();
  243. /*______________________________________________________*/
  244. /*            If not right Machine then stop            */
  245. /*______________________________________________________*/
  246.     OSys = SysEnvirons(VERSION,&theWorld);
  247.     /*if(!theWorld.hasColorQD) {
  248.         crashDia = GetNewDialog (nocolorID, nil, (WindowPtr) -1);
  249.         DrawDialog (crashDia);
  250.         Delay (300, tick);
  251.         ExitToShell();
  252.         }
  253.     if(theWorld.processor != env68020) {
  254.         crashDia = GetNewDialog (no68020, nil, (WindowPtr) -1);
  255.         DrawDialog (crashDia);
  256.         Delay (300, tick);
  257.         ExitToShell();
  258.         }
  259.     if(!theWorld.hasFPU) {
  260.         crashDia = GetNewDialog (no68881, nil, (WindowPtr) -1);
  261.         DrawDialog (crashDia);
  262.         Delay (300, tick);
  263.         ExitToShell();
  264.         }
  265.     if(theWorld.systemVersion < 0x0600) {
  266.         crashDia = GetNewDialog (nosys6, nil, (WindowPtr) -1);
  267.         DrawDialog (crashDia);
  268.         Delay (300, tick);
  269.         ExitToShell();
  270.         }*/
  271.             
  272. /*______________________________________________________*/
  273. /*                     Set Rects                        */
  274. /*______________________________________________________*/
  275.     screenRect = qd.screenBits.bounds;
  276.     offLeft = 0;
  277.     offTop = 0;
  278.     offRight = screenRect.right;
  279.     offBottom = screenRect.bottom;
  280.     SetRect(&BaseRect, 40, 60, 472, 282);
  281.     tempRgn = GetGrayRgn();
  282.     HLock ((Handle) tempRgn);
  283.     TotalRect = (**tempRgn).rgnBBox;
  284.     SetRect(&minRect, 80, 80, (**tempRgn).rgnBBox.right - 40, 
  285.                 (**tempRgn).rgnBBox.bottom - 40);
  286.     HUnlock ((Handle) tempRgn);
  287.  
  288. /*______________________________________________________*/
  289. /*        Open Window & set Palette & Picture           */
  290. /*______________________________________________________*/
  291.     theGDevice = GetMainDevice();
  292.     HLock ((Handle) theGDevice);
  293.     mycolors = (**(**theGDevice).gdPMap).pmTable;
  294.     numcolor = (**(**theGDevice).gdPMap).pixelSize;
  295.     HUnlock((Handle) theGDevice);
  296.     switch (numcolor) {
  297.         case 1:
  298.             numcolor = 2;
  299.             break;
  300.         case 2:
  301.             numcolor = 4;
  302.             break;
  303.         case 4:
  304.             numcolor = 16;
  305.             break;
  306.         case 8:
  307.             numcolor = 256;
  308.             break;
  309.         }
  310.     
  311.     myWindow = NewCWindow(nil, &BaseRect, (ConstStr255Param)"", TRUE, zoomDocProc, 
  312.                             (WindowPtr) -1, TRUE, 150);
  313.     SetPort((WindowPtr) myWindow);
  314.     DrawGrowIcon (myWindow);
  315.  
  316.     srcPalette = NewPalette (numcolor, mycolors, pmCourteous, 0);
  317.     SetPalette ((WindowPtr) myWindow, srcPalette, TRUE);
  318.     
  319. /*______________________________________________________*/
  320. /*                    Set menus                         */
  321. /*______________________________________________________*/
  322.     mymenu0 = GetMenu(appleID);
  323.     AppendResMenu(mymenu0, 'DRVR');
  324.     InsertMenu(mymenu0,0);
  325.     mymenu1 = NewMenu(129,(ConstStr255Param)"\pFile");
  326.     AppendMenu(mymenu1,(ConstStr255Param)"\pStart");
  327.     AppendMenu(mymenu1,(ConstStr255Param)"\pQuit");
  328.     InsertMenu(mymenu1,0);
  329.     mymenu2 = NewMenu(130,(ConstStr255Param)"\pEdit");
  330.     InsertMenu(mymenu2,0);
  331.     DrawMenuBar();
  332.  
  333. /*______________________________________________________*/
  334. /*                  Init variables                      */
  335. /*______________________________________________________*/
  336.     DoneFlag = FALSE;
  337.     yieldTime = 0;
  338.     return;
  339. }
  340.  
  341. void main(void)
  342. {
  343.     Boolean        track;
  344.     long        growResult;
  345. /*______________________________________________________*/
  346. /*                   Main Event loop                    */
  347. /*______________________________________________________*/
  348.     init();
  349.     for ( ;; ) {
  350.         if (DoneFlag) {
  351.             ExitToShell();
  352.             }
  353.         if (WaitNextEvent(everyEvent, &myEvent, yieldTime, nil)) {
  354.             switch (myEvent.what) {
  355.                 case mouseDown:
  356.                     switch (FindWindow(myEvent.where, &whichWindow)) {
  357.                         case inSysWindow:
  358.                             SystemClick(&myEvent, whichWindow);
  359.                             break;
  360.                         case inMenuBar:
  361.                             doCommand(MenuSelect(myEvent.where));
  362.                             break;
  363.                         case inContent:
  364.                             break;
  365.                         case inDrag:
  366.                             DragWindow (whichWindow, myEvent.where, &TotalRect);
  367.                             EraseRect (&whichWindow->portRect);
  368.                             DrawGrowIcon (whichWindow);
  369.                             break;
  370.                         case inGrow:
  371.                             growResult = GrowWindow (whichWindow, myEvent.where,
  372.                                                     &minRect);
  373.                             SizeWindow(whichWindow, LoWord(growResult), 
  374.                                     HiWord(growResult), TRUE);
  375.                             EraseRect (&whichWindow->portRect);
  376.                             DrawGrowIcon (whichWindow);
  377.                             break;
  378.                         case inGoAway:
  379.                             track = TrackGoAway (whichWindow, myEvent.where);
  380.                             if (track)
  381.                                 CloseWindow (whichWindow);
  382.                             break;
  383.                         case inZoomIn:
  384.                             track = TrackBox (whichWindow, myEvent.where, inZoomIn);
  385.                             if (track) {
  386.                                 ZoomWindow (whichWindow, inZoomIn, TRUE);
  387.                                 EraseRect (&whichWindow->portRect);
  388.                                 DrawGrowIcon (whichWindow);
  389.                                 }
  390.                             break;
  391.                         case inZoomOut:
  392.                             track = TrackBox (whichWindow, myEvent.where, inZoomOut);
  393.                             if (track) {
  394.                                 ZoomWindow (whichWindow, inZoomOut, TRUE);
  395.                                 EraseRect (&whichWindow->portRect);
  396.                                 DrawGrowIcon (whichWindow);
  397.                                 }
  398.                             break;
  399.                         default:
  400.                             break;
  401.                         }
  402.                     break;
  403.                 case keyDown:
  404.                     break;
  405.                 case autoKey:
  406.                     break;
  407.                 case updateEvt:
  408.                     if ((WindowPtr) myEvent.message == myWindow) {
  409.                         BeginUpdate((WindowPtr) myWindow);
  410.                         EndUpdate((WindowPtr) myWindow);
  411.                         }
  412.                     break;
  413.                 case diskEvt:
  414.                     break;
  415.                 case activateEvt:
  416.                     break;
  417.                 case 15:
  418.                     if ((myEvent.message << 31) == 0) { /* Suspend */
  419.                         yieldTime = 30;
  420.                         HideWindow((WindowPtr) myWindow);
  421.                         }
  422.                     else { /* Resume */
  423.                         yieldTime = 0;
  424.                         ShowWindow((WindowPtr) myWindow);
  425.                         SetPort((WindowPtr) myWindow);
  426.                         }
  427.                     break;
  428.                 default:
  429.                     break;
  430.                 }
  431.             }
  432.         }
  433. }